package com.seagull.core.http.controller;

import com.commons.api.APIResponse;
import com.commons.enums.ApiResponseEnum;
import com.commons.model.Page;
import com.commons.plugins.validation.base.Query;
import com.commons.plugins.validation.base.Update;
import com.seagull.core.http.controller.req.ReqBase;
import com.seagull.core.http.controller.req.ReqUser;
import com.seagull.core.http.service.CityService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2017/9/7.
 */
@RequestMapping("/test/")
@RestController
public class TestController {

    @Autowired
    private CityService cityService;

    @RequestMapping("query")
    public APIResponse test(@RequestBody ReqBase req){
        try {
            return APIResponse.returnSuccess(cityService.findAllCity(req));
        } catch (Exception e) {
            return APIResponse.returnFail(ApiResponseEnum.INTERNAL_ERROR);
        }
    }

    @RequestMapping("valid")
    public APIResponse testValid(@RequestBody @Validated(Update.class) ReqUser req){
        try {
            return APIResponse.returnSuccess(req.toString());
        } catch (Exception e) {
            return APIResponse.returnFail(ApiResponseEnum.INTERNAL_ERROR);
        }
    }
}
